home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / vidhrdw / btime.c < prev    next >
C/C++ Source or Header  |  2000-05-04  |  21KB  |  817 lines

  1. /***************************************************************************
  2.  
  3.     vidhrdw.c
  4.  
  5.     Functions to emulate the video hardware of the machine.
  6.  
  7. This file is also used by scregg.c
  8.  
  9. ***************************************************************************/
  10.  
  11. #include "driver.h"
  12. #include "vidhrdw/generic.h"
  13.  
  14.  
  15. unsigned char *lnc_charbank;
  16. unsigned char *bnj_backgroundram;
  17. unsigned char *zoar_scrollram;
  18. unsigned char *deco_charram;
  19. size_t bnj_backgroundram_size;
  20.  
  21. static int sprite_dirty[256];
  22. static int char_dirty[1024];
  23.  
  24. static int flipscreen = 0;
  25. static int btime_palette = 0;
  26. static unsigned char bnj_scroll1 = 0;
  27. static unsigned char bnj_scroll2 = 0;
  28. static unsigned char *dirtybuffer2 = 0;
  29. static struct osd_bitmap *background_bitmap;
  30. static int lnc_sound_interrupt_enabled = 0;
  31.  
  32. /***************************************************************************
  33.  
  34.     Burger Time doesn't have a color PROM. It uses RAM to dynamically
  35.     create the palette.
  36.     The palette RAM is connected to the RGB output this way:
  37.  
  38.     bit 7 -- 15 kohm resistor  -- BLUE (inverted)
  39.           -- 33 kohm resistor  -- BLUE (inverted)
  40.           -- 15 kohm resistor  -- GREEN (inverted)
  41.           -- 33 kohm resistor  -- GREEN (inverted)
  42.           -- 47 kohm resistor  -- GREEN (inverted)
  43.           -- 15 kohm resistor  -- RED (inverted)
  44.           -- 33 kohm resistor  -- RED (inverted)
  45.     bit 0 -- 47 kohm resistor  -- RED (inverted)
  46.  
  47. ***************************************************************************/
  48. void btime_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
  49. {
  50.     int i;
  51.  
  52.  
  53.     /* Burger Time doesn't have a color PROM, but Hamburge has. */
  54.     /* This function is also used by Eggs. */
  55.     if (color_prom == 0) return;
  56.  
  57.     for (i = 0;i < Machine->drv->total_colors;i++)
  58.     {
  59.         int bit0,bit1,bit2;
  60.  
  61.         /* red component */
  62.         bit0 = (*color_prom >> 0) & 0x01;
  63.         bit1 = (*color_prom >> 1) & 0x01;
  64.         bit2 = (*color_prom >> 2) & 0x01;
  65.         *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  66.         /* green component */
  67.         bit0 = (*color_prom >> 3) & 0x01;
  68.         bit1 = (*color_prom >> 4) & 0x01;
  69.         bit2 = (*color_prom >> 5) & 0x01;
  70.         *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  71.         /* blue component */
  72.         bit0 = 0;
  73.         bit1 = (*color_prom >> 6) & 0x01;
  74.         bit2 = (*color_prom >> 7) & 0x01;
  75.         *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  76.  
  77.         color_prom++;
  78.     }
  79. }
  80.  
  81. /***************************************************************************
  82.  
  83.     Convert the color PROMs into a more useable format.
  84.  
  85.     The PROM is connected to the RGB output this way:
  86.  
  87.     bit 7 -- 47 kohm resistor  -- RED
  88.           -- 33 kohm resistor  -- RED
  89.           -- 15 kohm resistor  -- RED
  90.           -- 47 kohm resistor  -- GREEN
  91.           -- 33 kohm resistor  -- GREEN
  92.           -- 15 kohm resistor  -- GREEN
  93.           -- 33 kohm resistor  -- BLUE
  94.     bit 0 -- 15 kohm resistor  -- BLUE
  95.  
  96. ***************************************************************************/
  97. void lnc_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
  98. {
  99.     int i;
  100.  
  101.  
  102.     for (i = 0;i < Machine->drv->total_colors;i++)
  103.     {
  104.         int bit0,bit1,bit2;
  105.  
  106.         /* red component */
  107.         bit0 = (*color_prom >> 7) & 0x01;
  108.         bit1 = (*color_prom >> 6) & 0x01;
  109.         bit2 = (*color_prom >> 5) & 0x01;
  110.         *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  111.         /* green component */
  112.         bit0 = (*color_prom >> 4) & 0x01;
  113.         bit1 = (*color_prom >> 3) & 0x01;
  114.         bit2 = (*color_prom >> 2) & 0x01;
  115.         *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  116.         /* blue component */
  117.         bit0 = 0;
  118.         bit1 = (*color_prom >> 1) & 0x01;
  119.         bit2 = (*color_prom >> 0) & 0x01;
  120.         *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  121.  
  122.         color_prom++;
  123.     }
  124. }
  125.  
  126.  
  127. void lnc_init_machine(void)
  128. {
  129.     *lnc_charbank = 1;
  130. }
  131.  
  132.  
  133. /***************************************************************************
  134.  
  135. Start the video hardware emulation.
  136.  
  137. ***************************************************************************/
  138. int bnj_vh_start (void)
  139. {
  140.     if (generic_vh_start() != 0)
  141.         return 1;
  142.  
  143.     if ((dirtybuffer2 = malloc(bnj_backgroundram_size)) == 0)
  144.     {
  145.         generic_vh_stop();
  146.         return 1;
  147.     }
  148.     memset(dirtybuffer2,1,bnj_backgroundram_size);
  149.  
  150.     /* the background area is twice as wide as the screen */
  151.     if ((background_bitmap = osd_create_bitmap(2*Machine->drv->screen_width,Machine->drv->screen_height)) == 0)
  152.     {
  153.         free(dirtybuffer2);
  154.         generic_vh_stop();
  155.         return 1;
  156.     }
  157.  
  158.     bnj_scroll1 = 0;
  159.     bnj_scroll2 = 0;
  160.  
  161.     return 0;
  162. }
  163.  
  164. int btime_vh_start (void)
  165. {
  166.     bnj_scroll1 = 0;
  167.     bnj_scroll2 = 0;
  168.  
  169.     return generic_vh_start();
  170. }
  171.  
  172. /***************************************************************************
  173.  
  174. Stop the video hardware emulation.
  175.  
  176. ***************************************************************************/
  177. void bnj_vh_stop (void)
  178. {
  179.     osd_free_bitmap(background_bitmap);
  180.     free(dirtybuffer2);
  181.     generic_vh_stop();
  182. }
  183.  
  184.  
  185. WRITE_HANDLER( btime_paletteram_w )
  186. {
  187.     /* RGB output is inverted */
  188.     paletteram_BBGGGRRR_w(offset,~data);
  189. }
  190.  
  191. WRITE_HANDLER( lnc_videoram_w )
  192. {
  193.     if (videoram[offset] != data || colorram[offset] != *lnc_charbank)
  194.     {
  195.         videoram[offset] = data;
  196.         colorram[offset] = *lnc_charbank;
  197.  
  198.         dirtybuffer[offset] = 1;
  199.     }
  200. }
  201.  
  202. READ_HANDLER( btime_mirrorvideoram_r )
  203. {
  204.     int x,y;
  205.  
  206.     /* swap x and y coordinates */
  207.     x = offset / 32;
  208.     y = offset % 32;
  209.     offset = 32 * y + x;
  210.  
  211.     return videoram_r(offset);
  212. }
  213.  
  214. READ_HANDLER( btime_mirrorcolorram_r )
  215. {
  216.     int x,y;
  217.  
  218.     /* swap x and y coordinates */
  219.     x = offset / 32;
  220.     y = offset % 32;
  221.     offset = 32 * y + x;
  222.  
  223.     return colorram_r(offset);
  224. }
  225.  
  226. WRITE_HANDLER( btime_mirrorvideoram_w )
  227. {
  228.     int x,y;
  229.  
  230.     /* swap x and y coordinates */
  231.     x = offset / 32;
  232.     y = offset % 32;
  233.     offset = 32 * y + x;
  234.  
  235.     videoram_w(offset,data);
  236. }
  237.  
  238. WRITE_HANDLER( lnc_mirrorvideoram_w )
  239. {
  240.     int x,y;
  241.  
  242.     /* swap x and y coordinates */
  243.     x = offset / 32;
  244.     y = offset % 32;
  245.     offset = 32 * y + x;
  246.  
  247.     lnc_videoram_w(offset,data);
  248. }
  249.  
  250. WRITE_HANDLER( btime_mirrorcolorram_w )
  251. {
  252.     int x,y;
  253.  
  254.     /* swap x and y coordinates */
  255.     x = offset / 32;
  256.     y = offset % 32;
  257.     offset = 32 * y + x;
  258.  
  259.     colorram_w(offset,data);
  260. }
  261.  
  262. WRITE_HANDLER( deco_charram_w )
  263. {
  264.     if (deco_charram[offset] == data)  return;
  265.  
  266.     deco_charram[offset] = data;
  267.  
  268.     offset &= 0x1fff;
  269.  
  270.     /* dirty sprite */
  271.     sprite_dirty[offset >> 5] = 1;
  272.  
  273.     /* diry char */
  274.     char_dirty  [offset >> 3] = 1;
  275. }
  276.  
  277. WRITE_HANDLER( bnj_background_w )
  278. {
  279.     if (bnj_backgroundram[offset] != data)
  280.     {
  281.         dirtybuffer2[offset] = 1;
  282.  
  283.         bnj_backgroundram[offset] = data;
  284.     }
  285. }
  286.  
  287. WRITE_HANDLER( bnj_scroll1_w )
  288. {
  289.     // Dirty screen if background is being turned off
  290.     if (bnj_scroll1 && !data)
  291.     {
  292.         memset(dirtybuffer,1,videoram_size);
  293.     }
  294.  
  295.     bnj_scroll1 = data;
  296. }
  297.  
  298. WRITE_HANDLER( bnj_scroll2_w )
  299. {
  300.     bnj_scroll2 = data;
  301. }
  302.  
  303. WRITE_HANDLER( zoar_video_control_w )
  304. {
  305.     // Zoar video control
  306.     //
  307.     // Bit 0-2 = Unknown (always 0). Marked as MCOL on schematics
  308.     // Bit 3-4 = Palette
  309.     // Bit 7   = Flip Screen
  310.  
  311.     static int video_control = -1;
  312.  
  313.     if (video_control != data)
  314.     {
  315.         memset(dirtybuffer,1,videoram_size);
  316.  
  317.         video_control = data;
  318.  
  319.         flipscreen =  data & 0x80;
  320.         btime_palette    = (data & 0x30) >> 3;
  321.     }
  322. }
  323.  
  324. WRITE_HANDLER( btime_video_control_w )
  325. {
  326.     // Btime video control
  327.     //
  328.     // Bit 0   = Flip screen
  329.     // Bit 1-7 = Unknown
  330.  
  331.     static int video_control = -1;
  332.  
  333.     if (video_control != data)
  334.     {
  335.         memset(dirtybuffer,1,videoram_size);
  336.  
  337.         // This is used by Bump'n'Jump
  338.         if (dirtybuffer2)
  339.         {
  340.             memset(dirtybuffer2,1,bnj_backgroundram_size);
  341.         }
  342.  
  343.         video_control = data;
  344.  
  345.         flipscreen = data & 0x01;
  346.     }
  347. }
  348.  
  349. WRITE_HANDLER( bnj_video_control_w )
  350. {
  351.     /* Bnj/Lnc works a little differently than the btime/eggs (apparently). */
  352.     /* According to the information at: */
  353.     /* http://www.davesclassics.com/arcade/Switch_Settings/BumpNJump.sw */
  354.     /* SW8 is used for cocktail video selection (as opposed to controls), */
  355.     /* but bit 7 of the input port is used for vblank input. */
  356.     /* My guess is that this switch open circuits some connection to */
  357.     /* the monitor hardware. */
  358.     /* For now we just check 0x40 in DSW1, and ignore the write if we */
  359.     /* are in upright controls mode. */
  360.  
  361.     if (input_port_3_r(0) & 0x40) /* cocktail mode */
  362.         btime_video_control_w(offset, data);
  363. }
  364.  
  365. WRITE_HANDLER( lnc_video_control_w )
  366. {
  367.     // I have a feeling that this only works by coincidence. I couldn't
  368.     // figure out how NMI's are disabled by the sound processor
  369.     lnc_sound_interrupt_enabled = data & 0x08;
  370.  
  371.     bnj_video_control_w(offset, data & 0x01);
  372. }
  373.  
  374. WRITE_HANDLER( disco_video_control_w )
  375. {
  376.     static int video_control = -1;
  377.  
  378.     if (video_control != data)
  379.     {
  380.         memset(dirtybuffer,1,videoram_size);
  381.  
  382.         video_control = data;
  383.  
  384.         btime_palette = (data >> 2) & 0x03;
  385.  
  386.         if (!(input_port_3_r(0) & 0x40)) /* cocktail mode */
  387.         {
  388.             flipscreen = data & 0x01;
  389.         }
  390.     }
  391. }
  392.  
  393.  
  394. int lnc_sound_interrupt(void)
  395. {
  396.     if (lnc_sound_interrupt_enabled)
  397.         return nmi_interrupt();
  398.     else
  399.         return ignore_interrupt();
  400. }
  401.  
  402.  
  403. /***************************************************************************
  404.  
  405. Draw the game screen in the given osd_bitmap.
  406. Do NOT call osd_update_display() from this function, it will be called by
  407. the main emulation engine.
  408.  
  409. ***************************************************************************/
  410. static void drawchars(struct osd_bitmap *bitmap, int transparency, int color, int priority)
  411. {
  412.     int offs;
  413.  
  414.     /* for every character in the Video RAM, check if it has been modified */
  415.     /* since last time and update it accordingly. If the background is on, */
  416.     /* draw characters as sprites */
  417.  
  418.     for (offs = videoram_size - 1;offs >= 0;offs--)
  419.     {
  420.         int sx,sy,code;
  421.  
  422.         if (!dirtybuffer[offs] && (bitmap == tmpbitmap)) continue;
  423.  
  424.         dirtybuffer[offs] = 0;
  425.  
  426.         code = videoram[offs] + 256 * (colorram[offs] & 3);
  427.  
  428.         /* check priority */
  429.         if ((priority != -1) && (priority != ((code >> 7) & 0x01)))  continue;
  430.  
  431.         sx = 31 - (offs / 32);
  432.         sy = offs % 32;
  433.  
  434.         if (flipscreen)
  435.         {
  436.             sx = 31 - sx;
  437.             sy = 31 - sy;
  438.         }
  439.  
  440.         drawgfx(bitmap,Machine->gfx[0],
  441.                 code,
  442.                 color,
  443.                 flipscreen,flipscreen,
  444.                 8*sx,8*sy,
  445.                 &Machine->drv->visible_area,transparency,0);
  446.     }
  447. }
  448.  
  449. static void drawsprites(struct osd_bitmap *bitmap, int color,
  450.                         int sprite_y_adjust, int sprite_y_adjust_flipscreen,
  451.                         unsigned char *sprite_ram, int interleave)
  452. {
  453.     int i,offs;
  454.  
  455.     /* Draw the sprites */
  456.     for (i = 0, offs = 0;i < 8; i++, offs += 4*interleave)
  457.     {
  458.         int sx,sy,flipx,flipy;
  459.  
  460.         if (!(sprite_ram[offs + 0] & 0x01)) continue;
  461.  
  462.         sx = 240 - sprite_ram[offs + 3*interleave];
  463.         sy = 240 - sprite_ram[offs + 2*interleave];
  464.  
  465.         flipx = sprite_ram[offs + 0] & 0x04;
  466.         flipy = sprite_ram[offs + 0] & 0x02;
  467.  
  468.         if (flipscreen)
  469.         {
  470.             sx = 240 - sx;
  471.             sy = 240 - sy + sprite_y_adjust_flipscreen;
  472.  
  473.             flipx = !flipx;
  474.             flipy = !flipy;
  475.         }
  476.  
  477.         sy -= sprite_y_adjust;
  478.  
  479.         drawgfx(bitmap,Machine->gfx[1],
  480.                 sprite_ram[offs + interleave],
  481.                 color,
  482.                 flipx,flipy,
  483.                 sx,sy,
  484.                 &Machine->drv->visible_area,TRANSPARENCY_PEN,0);
  485.  
  486.         sy += (flipscreen ? -256 : 256);
  487.  
  488.         // Wrap around
  489.         drawgfx(bitmap,Machine->gfx[1],
  490.                 sprite_ram[offs + interleave],
  491.                 color,
  492.                 flipx,flipy,
  493.                 sx,sy,
  494.                 &Machine->drv->visible_area,TRANSPARENCY_PEN,0);
  495.     }
  496. }
  497.  
  498.  
  499. static void drawbackground(struct osd_bitmap *bitmap, unsigned char* tilemap)
  500. {
  501.     int i, offs;
  502.  
  503.     int scroll = -(bnj_scroll2 | ((bnj_scroll1 & 0x03) << 8));
  504.  
  505.     // One extra iteration for wrap around
  506.     for (i = 0; i < 5; i++, scroll += 256)
  507.     {
  508.         int tileoffset = tilemap[i & 3] * 0x100;
  509.  
  510.         // Skip if this title is completely off the screen
  511.         if (scroll > 256)  break;
  512.         if (scroll < -256) continue;
  513.  
  514.         for (offs = 0; offs < 0x100; offs++)
  515.         {
  516.             int sx,sy;
  517.  
  518.             sx = 240 - (16 * (offs / 16) + scroll);
  519.             sy = 16 * (offs % 16);
  520.  
  521.             if (flipscreen)
  522.             {
  523.                 sx = 240 - sx;
  524.                 sy = 240 - sy;
  525.             }
  526.  
  527.             drawgfx(bitmap, Machine->gfx[2],
  528.                     memory_region(REGION_GFX3)[tileoffset + offs],
  529.                     btime_palette,
  530.                     flipscreen,flipscreen,
  531.                     sx,sy,
  532.                     0,TRANSPARENCY_NONE,0);
  533.         }
  534.     }
  535. }
  536.  
  537.  
  538. static void decode_modified(unsigned char *sprite_ram, int interleave)
  539. {
  540.     int i,offs;
  541.  
  542.  
  543.     /* decode dirty characters */
  544.     for (offs = videoram_size - 1;offs >= 0;offs--)
  545.     {
  546.         int code;
  547.  
  548.         code = videoram[offs] + 256 * (colorram[offs] & 3);
  549.  
  550.         switch (char_dirty[code])
  551.         {
  552.         case 1:
  553.             decodechar(Machine->gfx[0],code,deco_charram,Machine->drv->gfxdecodeinfo[0].gfxlayout);
  554.             char_dirty[code] = 2;
  555.             /* fall through */
  556.         case 2:
  557.             dirtybuffer[offs] = 1;
  558.             break;
  559.         default:
  560.             break;
  561.         }
  562.     }
  563.  
  564.     for (i = 0; i < sizeof(char_dirty); i++)
  565.     {
  566.         if (char_dirty[i] == 2)  char_dirty[i] = 0;
  567.     }
  568.  
  569.     /* decode dirty sprites */
  570.     for (i = 0, offs = 0;i < 8; i++, offs += 4*interleave)
  571.     {
  572.         int code;
  573.  
  574.         code  = sprite_ram[offs + interleave];
  575.         if (sprite_dirty[code])
  576.         {
  577.             sprite_dirty[code] = 0;
  578.  
  579.             decodechar(Machine->gfx[1],code,deco_charram,Machine->drv->gfxdecodeinfo[1].gfxlayout);
  580.         }
  581.     }
  582. }
  583.  
  584.  
  585. void btime_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  586. {
  587.     if (palette_recalc())
  588.         memset(dirtybuffer,1,videoram_size);
  589.  
  590.     if (bnj_scroll1 & 0x10)
  591.     {
  592.         int i, start;
  593.  
  594.         // Generate tile map
  595.         static unsigned char btime_tilemap[4];
  596.  
  597.         if (flipscreen)
  598.             start = 0;
  599.         else
  600.             start = 1;
  601.  
  602.         for (i = 0; i < 4; i++)
  603.         {
  604.             btime_tilemap[i] = start | (bnj_scroll1 & 0x04);
  605.             start = (++start & 0x03);
  606.         }
  607.  
  608.         drawbackground(bitmap, btime_tilemap);
  609.  
  610.         drawchars(bitmap, TRANSPARENCY_PEN, 0, -1);
  611.     }
  612.     else
  613.     {
  614.         drawchars(tmpbitmap, TRANSPARENCY_NONE, 0, -1);
  615.  
  616.         /* copy the temporary bitmap to the screen */
  617.         copybitmap(bitmap,tmpbitmap,0,0,0,0,&Machine->drv->visible_area,TRANSPARENCY_NONE,0);
  618.     }
  619.  
  620.     drawsprites(bitmap, 0, 1, 0, videoram, 0x20);
  621. }
  622.  
  623.  
  624. void eggs_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  625. {
  626.     if (palette_recalc())
  627.         memset(dirtybuffer,1,videoram_size);
  628.  
  629.     drawchars(tmpbitmap, TRANSPARENCY_NONE, 0, -1);
  630.  
  631.     /* copy the temporary bitmap to the screen */
  632.     copybitmap(bitmap,tmpbitmap,0,0,0,0,&Machine->drv->visible_area,TRANSPARENCY_NONE,0);
  633.  
  634.     drawsprites(bitmap, 0, 0, 0, videoram, 0x20);
  635. }
  636.  
  637.  
  638. void lnc_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  639. {
  640.     if (palette_recalc())
  641.         memset(dirtybuffer,1,videoram_size);
  642.  
  643.     drawchars(tmpbitmap, TRANSPARENCY_NONE, 0, -1);
  644.  
  645.     /* copy the temporary bitmap to the screen */
  646.     copybitmap(bitmap,tmpbitmap,0,0,0,0,&Machine->drv->visible_area,TRANSPARENCY_NONE,0);
  647.  
  648.     drawsprites(bitmap, 0, 1, 2, videoram, 0x20);
  649. }
  650.  
  651.  
  652. void zoar_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  653. {
  654.     if (palette_recalc())
  655.         memset(dirtybuffer,1,videoram_size);
  656.  
  657.     if (bnj_scroll1 & 0x04)
  658.     {
  659.         drawbackground(bitmap, zoar_scrollram);
  660.  
  661.         drawchars(bitmap, TRANSPARENCY_PEN, btime_palette + 1, -1);
  662.     }
  663.     else
  664.     {
  665.         drawchars(tmpbitmap, TRANSPARENCY_NONE, btime_palette + 1, -1);
  666.  
  667.         /* copy the temporary bitmap to the screen */
  668.         copybitmap(bitmap,tmpbitmap,0,0,0,0,&Machine->drv->visible_area,TRANSPARENCY_NONE,0);
  669.     }
  670.  
  671.     /* The order is important for correct priorities */
  672.     drawsprites(bitmap, btime_palette + 1, 1, 2, videoram + 0x1f, 0x20);
  673.     drawsprites(bitmap, btime_palette + 1, 1, 2, videoram,        0x20);
  674. }
  675.  
  676.  
  677. void bnj_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  678. {
  679.     if (palette_recalc())
  680.     {
  681.         memset(dirtybuffer,1,videoram_size);
  682.         memset(dirtybuffer2,1,bnj_backgroundram_size);
  683.     }
  684.  
  685.     /*
  686.      *  For each character in the background RAM, check if it has been
  687.      *  modified since last time and update it accordingly.
  688.      */
  689.     if (bnj_scroll1)
  690.     {
  691.         int scroll, offs;
  692.  
  693.         for (offs = bnj_backgroundram_size-1; offs >=0; offs--)
  694.         {
  695.             int sx,sy;
  696.  
  697.             if (!dirtybuffer2[offs]) continue;
  698.  
  699.             dirtybuffer2[offs] = 0;
  700.  
  701.             sx = 16 * ((offs < 0x100) ? ((offs % 0x80) / 8) : ((offs % 0x80) / 8) + 16);
  702.             sy = 16 * (((offs % 0x100) < 0x80) ? offs % 8 : (offs % 8) + 8);
  703.             sx = 496 - sx;
  704.  
  705.             if (flipscreen)
  706.             {
  707.                 sx = 496 - sx;
  708.                 sy = 240 - sy;
  709.             }
  710.  
  711.             drawgfx(background_bitmap, Machine->gfx[2],
  712.                     (bnj_backgroundram[offs] >> 4) + ((offs & 0x80) >> 3) + 32,
  713.                     0,
  714.                     flipscreen, flipscreen,
  715.                     sx, sy,
  716.                     0, TRANSPARENCY_NONE, 0);
  717.         }
  718.  
  719.         /* copy the background bitmap to the screen */
  720.         scroll = (bnj_scroll1 & 0x02) * 128 + 511 - bnj_scroll2;
  721.         if (!flipscreen)
  722.             scroll = 767-scroll;
  723.         copyscrollbitmap (bitmap, background_bitmap, 1, &scroll, 0, 0, &Machine->drv->visible_area,TRANSPARENCY_NONE, 0);
  724.  
  725.         /* copy the low priority characters followed by the sprites
  726.            then the high priority characters */
  727.         drawchars(bitmap, TRANSPARENCY_PEN, 0, 1);
  728.         drawsprites(bitmap, 0, 0, 0, videoram, 0x20);
  729.         drawchars(bitmap, TRANSPARENCY_PEN, 0, 0);
  730.     }
  731.     else
  732.     {
  733.         drawchars(tmpbitmap, TRANSPARENCY_NONE, 0, -1);
  734.  
  735.         /* copy the temporary bitmap to the screen */
  736.         copybitmap(bitmap,tmpbitmap,0,0,0,0,&Machine->drv->visible_area,TRANSPARENCY_NONE,0);
  737.  
  738.         drawsprites(bitmap, 0, 0, 0, videoram, 0x20);
  739.     }
  740. }
  741.  
  742.  
  743. void cookrace_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  744. {
  745.     int offs;
  746.  
  747.  
  748.     if (palette_recalc())
  749.         memset(dirtybuffer,1,videoram_size);
  750.  
  751.     /*
  752.      *  For each character in the background RAM, check if it has been
  753.      *  modified since last time and update it accordingly.
  754.      */
  755.     for (offs = bnj_backgroundram_size-1; offs >=0; offs--)
  756.     {
  757.         int sx,sy;
  758.  
  759.         sx = 31 - (offs / 32);
  760.         sy = offs % 32;
  761.  
  762.         if (flipscreen)
  763.         {
  764.             sx = 31 - sx;
  765.             sy = 31 - sy;
  766.         }
  767.  
  768.         drawgfx(bitmap, Machine->gfx[2],
  769.                 bnj_backgroundram[offs],
  770.                 0,
  771.                 flipscreen, flipscreen,
  772.                 8*sx,8*sy,
  773.                 0, TRANSPARENCY_NONE, 0);
  774.     }
  775.  
  776.     drawchars(bitmap, TRANSPARENCY_PEN, 0, -1);
  777.  
  778.     drawsprites(bitmap, 0, 1, 0, videoram, 0x20);
  779. }
  780.  
  781.  
  782. void disco_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  783. {
  784.     if (palette_recalc())
  785.         memset(dirtybuffer,1,videoram_size);
  786.  
  787.     decode_modified(spriteram, 1);
  788.  
  789.     drawchars(tmpbitmap, TRANSPARENCY_NONE, btime_palette, -1);
  790.  
  791.     /* copy the temporary bitmap to the screen */
  792.     copybitmap(bitmap,tmpbitmap,0,0,0,0,&Machine->drv->visible_area,TRANSPARENCY_NONE,0);
  793.  
  794.     drawsprites(bitmap, btime_palette, 0, 0, spriteram, 1);
  795. }
  796.  
  797.  
  798.  
  799.  
  800.  
  801.  
  802.  
  803. void decocass_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  804. {
  805.     if (palette_recalc())
  806.         memset(dirtybuffer,1,videoram_size);
  807.  
  808.     decode_modified(videoram, 0x20);
  809.  
  810.     drawchars(tmpbitmap, TRANSPARENCY_NONE, 0, -1);
  811.  
  812.     /* copy the temporary bitmap to the screen */
  813.     copybitmap(bitmap,tmpbitmap,0,0,0,0,&Machine->drv->visible_area,TRANSPARENCY_NONE,0);
  814.  
  815.     drawsprites(bitmap, 0, 0, 0, videoram, 0x20);
  816. }
  817.